package com.texplose.service.impl;

import com.texplose.entity.Category;
import com.texplose.entity.Recipe;
import com.texplose.entity.vo.CategoryParentPickerVo;
import com.texplose.entity.vo.CategoryParentVo;
import com.texplose.entity.vo.IndexCardsVo;
import com.texplose.entity.vo.ResponseResult;
import com.texplose.mapper.CategoryMapper;
import com.texplose.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : lyj
 * @Timer : 2022/5/17
 * @Description :
 */
@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;


    @Override
    public ResponseResult getRootCategory() {
        List<Category> rootCategories = categoryMapper.getRootCategory();
        return ResponseResult.okResult(rootCategories);
    }

    @Override
    public ResponseResult getChildrenById(Integer id) {
        CategoryParentVo categoryParentVo = categoryMapper.getChildrenById(id);
        return ResponseResult.okResult(categoryParentVo);
    }

    @Override
    public ResponseResult getCategoryList() {
        List<CategoryParentVo> categoryParentVos = categoryMapper.getCategoryList();
        return ResponseResult.okResult(categoryParentVos);
    }

    @Override
    public ResponseResult deleteCategoryById(Integer id) {
        categoryMapper.deleteCategoryById(id);
        return ResponseResult.okResult();
    }

    @Override
    public ResponseResult insertCategory(Category category) {
        categoryMapper.insertCategory(category);
        return ResponseResult.okResult();
    }

    @Override
    public ResponseResult updateCategory(Category category) {
        categoryMapper.updateCategory(category);
        return ResponseResult.okResult();
    }

    @Override
    public ResponseResult getRecipeListById(Integer id) {

        return ResponseResult.okResult();
    }

    @Override
    public ResponseResult getCategoryDetail(Integer id) {
        List<IndexCardsVo> recipes = categoryMapper.getCategoryDetail(id);
        return ResponseResult.okResult(recipes);
    }

    @Override
    public ResponseResult getCategoryPicker() {
        List<CategoryParentPickerVo> pickerVos = categoryMapper.getCategoryPicker();
        return ResponseResult.okResult(pickerVos);
    }
}
